const sass = require('sass')
const loadGruntTasks = require('load-grunt-tasks')
let data = {
  menus: [{
      name: 'Home',
      icon: 'aperture',
      link: 'index.html'
    },
    {
      name: 'Features',
      link: 'features.html'
    },
    {
      name: 'About',
      link: 'about.html'
    },
    {
      name: 'Contact',
      link: '#',
      children: [{
          name: 'Twitter',
          link: 'https://twitter.com/w_zce'
        },
        {
          name: 'About',
          link: 'https://weibo.com/zceme'
        },
        {
          name: 'divider'
        },
        {
          name: 'About',
          link: 'https://github.com/zce'
        }
      ]
    }
  ],
  pkg: require('./package.json'),
  date: new Date()
}
module.exports = grunt => {
  grunt.initConfig({
    clean:{
      temp:'code/grunt/**'
    },
    useref: {
      // specify which files contain the build blocks
      html: 'code/grunt/**/*.html',
      // explicitly specify the temp directory you are working in
      // this is the the base of your links ( "/" )
      temp: 'code/grunt',
    },
    swigtemplates:{
      options:{
        defaultContext: data,
        templatesDir: 'code/src/grunt'
      },
      index:{
          dest:'code/grunt/',
          src:['code/src/grunt/index.html','code/src/grunt/about.html'],
      }
    },
    copy:{
      ext: {
        files: [
          // {
          //   expand: true,
          //   cwd: 'code/src/grunt',
          //   src: ['*.html'],
          //   dest: 'code/grunt'
          // },
          {
            expand: true,
            cwd: 'code/src/grunt/assets/images',
            src: ['**'],
            dest: 'code/grunt/assets/images'
          },
          {
            expand: true,
            cwd: 'code/src/grunt/assets/fonts',
            src: ['**'],
            dest: 'code/grunt/assets/fonts'
          },
          {
            expand: true,
            cwd: 'code/public',
            src: ['**'],
            dest: 'code/grunt/'
          }
        ]
      }
    },
    sass:{
      options:{
        implementation: sass
      },
      dist:{
        files: [
          {
            expand:true,
            cwd:'code/src/grunt/assets/styles',
            src:['*.scss'],
            dest:'code/grunt/assets/styles',
            ext:'.css'
          }
        ]
      }
    },
    babel:{
      options:{
        presets: ['@babel/preset-env']
      },
      main:{
        files:[
          {
            expand:true,
            cwd:'code/src/grunt/assets/scripts',
            src:['*.js'],
            dest:'code/grunt/assets/scripts',
            ext:'.js'
          }
        ]
      }
    }
  })
  // grunt.loadNpmTasks('grunt-sass')
  loadGruntTasks(grunt)
  grunt.registerTask('default',['clean','sass','babel','copy','swigtemplates','useref','concat','uglify','cssmin'])
}